import java.io.*;
import java.util.Random;

public class DataMaker {
    public static int[][] readData(String filename,int cityNum) throws IOException {
        // 读取数据
        int[] x;
        int[] y;
        String strbuff;
        BufferedReader data = new BufferedReader(new InputStreamReader(
                new FileInputStream(filename)));
        int[][] distance = new int[cityNum][cityNum];
        x = new int[cityNum];
        y = new int[cityNum];
        for (int i = 0; i < cityNum; i++) {
            // 读取一行数据，数据格式1 6734 1453
            strbuff = data.readLine();
            // 字符分割
            String[] strcol = strbuff.split(" ");
            x[i] = Integer.valueOf(strcol[1]);// x坐标
            y[i] = Integer.valueOf(strcol[2]);// y坐标
        }
        // 计算距离矩阵
        // ，针对具体问题，距离计算方法也不一样，此处用的是att48作为案例，它有48个城市，距离计算方法为伪欧氏距离，最优值为10628
        for (int i = 0; i < cityNum - 1; i++) {
            distance[i][i] = 0; // 对角线为0
            for (int j = i + 1; j < cityNum; j++) {
                double rij = Math
                        .sqrt(((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j])
                                * (y[i] - y[j])) / 10.0);
                // 四舍五入，取整
                int tij = (int) Math.round(rij);
                if (tij < rij) {
                    distance[i][j] = tij + 1;
                    distance[j][i] = distance[i][j];
                } else {
                    distance[i][j] = tij;
                    distance[j][i] = distance[i][j];
                }
            }
        }
        distance[cityNum - 1][cityNum - 1] = 0;
        return distance;

    }
    public static int[][] readDist(String filename,int cityNum){
        int[][] distance = new int[cityNum][cityNum];
        try (
                BufferedReader bufferedReader = new BufferedReader(new FileReader(filename));
                ){
            String line;
            int m=0;
            int n=0;
            while ((line=bufferedReader.readLine())!=null){
                System.out.println(line);
                for (String date:line.split(" ")){
                    distance[m][n++]=Integer.parseInt(date);
                }
                m++;n=0;
            }
            return distance;
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return distance;
    }
    public static void main(String[] args) {
        try(
            BufferedReader bufferedReader = new BufferedReader(new FileReader("data.txt"));
            BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter("data1.txt"));
            ) {
            String line = bufferedReader.readLine();
            if (line!=null){
                int cnt=1;
                String l="";
                for (String data:line.split(" ")){
                    l=l+data+(cnt%3==0?'\n':' ');
                    if (cnt%3==0){
                        bufferedWriter.write(l);
                        l="";
                    }
                    cnt++;
                }
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
